<?php
	class News_model extends CI_Model{

	 	function __construct(){
        	parent::__construct();
    	}

		function get_news_list($limit = 0, $offset = 0, $conditions = array()){
    	$where = "status = 1";
      if(!empty($conditions['title']) != '') $where .= " AND title LIKE '%{$conditions['title']}%'";
      if(!empty($conditions['school_id']) != '') $where .= " AND school_id = '{$conditions['school_id']}'";
      $sql = "SELECT SQL_CALC_FOUND_ROWS * FROM {$this->db->dbprefix}news WHERE $where ORDER BY id DESC ";
      if($limit > 0 || $offset > 0){
          $sql .= "LIMIT $limit, $offset";
      }
      $result = $this->db->query($sql)->result_array();
      $row_num =  $this->db->query('SELECT FOUND_ROWS() as row_num;')->row_array();
      return array("count" => $row_num['row_num'], "result" => $result);
    }
  }
